#ifndef BASE_UDP_SOCKET_H_
#define BASE_UDP_SOCKET_H_
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <string>
#include <errno.h>
#include <sys/select.h>
#include <sys/poll.h>
#include <vector>

#include "ctType.h"
#include "ct_noncopyable.h"
#include "Zebra.h"

class ctUDPSocket : private ctNoncopyable
{
        public:
                ctUDPSocket()
                {
                        socket_ = 0;
                        ifname_ = "";
                        ip_ = "";
                        port_ = 0;
                }
                ~ctUDPSocket();
                bool createSocket(const int port, const std::string &ip);
                int getSocket() { return socket_; }

                int sendData(struct sockaddr_in *clientaddr, const BYTE *data, const DWORD size);
                int recvData(BYTE *buffer, DWORD bufferlen, sockaddr_in *clientaddr);

                const char *getIPByIfName(const char *ifName);

        public:
                static const int T_RD_MSEC	= 2100;			//rd time out msec
                static const int T_WR_MSEC	= 2100;			//wr time out msec
                static const DWORD PH_LEN	= sizeof(DWORD);	//head len

        private:
                int socket_;
                struct sockaddr_in local_addr_;
                std::string ifname_;
                std::string ip_;
                int port_;
};

#endif //BASE_UDP_SOCKET_H_
